package com.pathfinder.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import com.pathfinder.GameClient;
import com.pathfinder.R;
import com.pathfinder.RequestSender;
import com.pathfinder.model.PlayerRole;

import static com.pathfinder.RequestSender.sendUpdatePlayerInfoRequest;

/**
 * Date: 10.05.11
 *
 * @author Victor Passichenko (vpas@yandex-team.ru)
 */
public class GameLobbyActivity extends Activity {
    public GameLobbyActivity() {
        super();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.game_lobby);

        TextView gameNameLabel = (TextView) findViewById(R.id.GameNameLabel);
        gameNameLabel.setText("Game: " + GameClient.getGame().getName());

        TextView playerNameLabel = (TextView) findViewById(R.id.PlayerNameLabel);
        playerNameLabel.setText("Player: " + GameClient.getPlayer().getInfo().getName());

        Spinner playerRoleSpinner = (Spinner) findViewById(R.id.PlayerRoleSpinner);
        final String[] roles = new String[]{PlayerRole.HUNTER.name(), PlayerRole.VICTIM.name()};
        playerRoleSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, roles));
        playerRoleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
                PlayerRole role = PlayerRole.valueOf(roles[position].toUpperCase());
                GameClient.getPlayer().getInfo().setRole(role);
                sendUpdatePlayerInfoRequest(GameClient.getPlayer());
            }

            public void onNothingSelected(AdapterView<?> adapterView) {
                // TODO
            }
        });

        Spinner playerColorSpinner = (Spinner) findViewById(R.id.PlayerColorSpinner);
        final String[] colors = new String[]{"red", "blue", "green", "yellow", "brown", "grey", "white"};
        playerColorSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, colors));
        playerColorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
                String color = colors[position];
                GameClient.getPlayer().getInfo().setColorByName(color);
                sendUpdatePlayerInfoRequest(GameClient.getPlayer());
            }

            public void onNothingSelected(AdapterView<?> adapterView) {
                // TODO
            }
        });


        CheckBox isReadyCheckBox = (CheckBox) findViewById(R.id.PlayerIsReadyCheckBox);
        isReadyCheckBox.setChecked(GameClient.getPlayer().isReady());
        isReadyCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                GameClient.getPlayer().setReady(isChecked);
                RequestSender.sendPlayerSetIsReadyRequest(GameClient.getPlayer());
            }
        });

        
    }


}
